package com.meihua.shellapp.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.lzy.okgo.model.Response;
import com.meihua.shellapp.R;
import com.meihua.shellapp.base.BaseActivity;
import com.meihua.shellapp.base.MyApplication;
import com.meihua.shellapp.bean.BuyOptBean;
import com.meihua.shellapp.common.Constant;
import com.meihua.shellapp.common.NetHelper;
import com.meihua.shellapp.utils.PicassoUtils;
import com.meihua.shellapp.utils.URL;

import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * 订单支付
 */

public class OrderPayActivity extends BaseActivity {
    @Bind(R.id.iv_top_left)
    ImageView iv_top_left;//返回
    @Bind(R.id.tv_title)
    TextView tv_title;//标题
    @Bind(R.id.orderpay_iv_ava)
    ImageView orderpayIvAva;
    @Bind(R.id.orderpay_tv_good_money)
    TextView orderpayTvGoodMoney;
    @Bind(R.id.orderpay_tv_good_name)
    TextView orderpayTvGoodName;
    String orderNum;//订单号

    @Override
    public int getLayoutId() {
        return R.layout.activity_order_pay;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        iv_top_left.setVisibility(View.VISIBLE);
        iv_top_left.setOnClickListener(this);
        tv_title.setVisibility(View.VISIBLE);
        tv_title.setText("订单支付");
        orderNum = getIntent().getStringExtra(Constant.ORDERNUM);
        getServerData();
    }

    /*获取服务器数据*/
    private void getServerData() {
        Map<String, String> params = new HashMap() {{
            put("order_num", orderNum);
        }};
        NetHelper.post(URL.getUrl().BUYOPT, params, new NetHelper.HttpCallBack() {
            @Override
            public void onSuccess(Response<String> response) {
                BuyOptBean bean = MyApplication.getInstance().getBeanForJson(BuyOptBean.class, response.body());
                if (bean == null) return;
                if (null != bean.getData()) {
                    PicassoUtils.getInstance().bindImageData(orderpayIvAva, bean.getData().getProduct_img());
//                    Picasso.with(OrderPayActivity.this).load(Constant.IMGSTR+bean.getData().getProduct_img()).into(orderpayIvAva);
                    orderpayTvGoodMoney.setText(bean.getData().getPay_money());
                    orderpayTvGoodName.setText(bean.getData().getProduct_name());
                }
            }
        }, false);
    }

    /*界面点击事件*/
    @OnClick({R.id.orderpay_iv_wx, R.id.orderpay_iv_alipay, R.id.orderpay_ll_confirm, R.id.iv_top_left})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_top_left:
                finish();
                break;
            case R.id.orderpay_iv_wx:
                //微信支付
                break;
            case R.id.orderpay_iv_alipay:
                //支付宝支付
                break;
            case R.id.orderpay_ll_confirm:
                //确认
                break;
        }
    }
}
